﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace HMViewerWPF
{
    /// <summary>
    /// Interaction logic for SettingsWindow.xaml
    /// </summary>
    public partial class SettingsWindow : Window
    {

        

        public SettingsWindow()
        {
            InitializeComponent();

            // Define in which mode to start the data monitoring after the Setting Windows has been closed
            //0 do not start,1 start in PS,2 start in FT, 3 Start in Winamax, 4 for Everest Poker
            Tag = 1; //starting in ps by default

        }

        private void GridLoaded(object sender, RoutedEventArgs e)
        {
            //loading settings from config file
            txtServerAdress.Text = Properties.Settings.Default.HMServerAdress;
            txtServerPort.Text = Properties.Settings.Default.HMServerPort;
            txtDBName.Text = Properties.Settings.Default.HMDataBaseName;
            txtSDLogin.Text = Properties.Settings.Default.HMServerLogin;
            txtDBPassword.Text = Properties.Settings.Default.HMServerPassword;
            txtPlayerNameFT.Text = Properties.Settings.Default.PlayerName_FT;
            txtPlayerNamePS.Text = Properties.Settings.Default.PlayerName_PS;
            txtPlayerNameWNM.Text = Properties.Settings.Default.PlayerName_WNM;
            txtPlayerNameEVT.Text = Properties.Settings.Default.PlayerName_EVY;

            cboStarIn.SelectedIndex = Properties.Settings.Default.StartWith;

            txtRefreshSeconds.Text = Properties.Settings.Default.RefreshSeconds.ToString();

            btnSaveAndStart.Focus();

        }

        private void BtnSaveAndStartClick(object sender, RoutedEventArgs e)
        {
            //Saving settings from config file
            Properties.Settings.Default.HMServerAdress = txtServerAdress.Text;
            Properties.Settings.Default.HMServerPort = txtServerPort.Text;
            Properties.Settings.Default.HMDataBaseName = txtDBName.Text;
            Properties.Settings.Default.HMServerLogin = txtSDLogin.Text;

            Properties.Settings.Default.HMServerPassword = txtDBPassword.Text;
            Properties.Settings.Default.PlayerName_FT = txtPlayerNameFT.Text;
            Properties.Settings.Default.PlayerName_PS = txtPlayerNamePS.Text;
            Properties.Settings.Default.PlayerName_WNM = txtPlayerNameWNM.Text;
            Properties.Settings.Default.PlayerName_EVY = txtPlayerNameEVT.Text;

            Properties.Settings.Default.StartWith = cboStarIn.SelectedIndex ;
            
            Properties.Settings.Default.RefreshSeconds = Convert.ToInt16(txtRefreshSeconds.Text);



            //saving
            Properties.Settings.Default.Save();

            this.Close();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Application.Current.Shutdown();
        }
    }
}
